using System;
using System.Collections.Generic;
using System.Text;
using RapidHDL;

namespace SimpleCounter
{
    class HardwareSoftwareInterface
    {
        ToplevelHardware oHardware;

        public bool LoadHardware()
        {
            oHardware = new ToplevelHardware();
            if (!oHardware.StartRapidHardware())
            {
                oHardware.Transcript.AddTranscript("Hardware failed to ininitilize.");
                string sTranscript = oHardware.Transcript.GetTranscript();
                System.Windows.Forms.MessageBox.Show(sTranscript,"Start Hardware Error",System.Windows.Forms.MessageBoxButtons.OK);
                return false;
            }
            return true;
        }

        public void StepClock()
        {
            oHardware.FPGAInterface.Go(1);
        }

        public void Reset()
        {
            oHardware.FPGAInterface.Reset();
        }

        public void SetEnable(bool bEnable)
        {
            SignalSource oEnable = oHardware.SystemInterface.GetSignalSource("I_ENABLE");
            if (bEnable)
                oEnable.ValueAsInt = 1;
            else
                oEnable.ValueAsInt = 0;

        }

        public int ReadCounter()
        {
            string sValue = oHardware.SystemInterface.GetSignalView("O_COUNT").FormattedValue;
            return System.Convert.ToInt32(sValue);
        }

        public void ViewHardware()
        {
            oHardware.LaunchGUI(false);
        }

    }
}
